#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Author   : 李吉凯
@Email    : lijikai1206@163.com
@Time     : 2021/7/11 18:44
@File     : FeishuKnowledage.py
'''
import json
from service.FeishuApi.baseRequest.BaseFeishu import BaseFeishu



class FeishuKnowledage(BaseFeishu):
    def __init__(self):
        BaseFeishu.__init__(self)

    def create_knowleadge(self, id, question, answer, content, tags):
        print(id, question, answer, content, tags)
        url = 'https://open.feishu.cn/open-apis/helpdesk/v1/faqs'
        header = {
            'Authorization': f'Bearer {self.token}',
            'Content-Type': 'application/json; charset=utf-8',
            'Header Key': 'X-Lark-Helpdesk-Authorization',
            # base64(helpdesk_id: helpdesk_token)
            'Header Value': self.res02
        }
        richtext = [
            {
                "content": content["content"],
                "type": content["type"]
            }
        ]
        params = {
            "faq": {
                "category_id": id,
                "question": question,
                "answer": answer,
                "answer_richtext": json.dumps(richtext),
                "tags": tags
            }
        }
        res = self.kl_req.post(url, data=params, headers=header)
        print('res:', res)
        print('res_Text', res.json())
        return res
